package com.hdfs.api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;



import java.io.IOException;

//读取hdfs文件的内容
public class HDFSReadDemo {


    public static void main(String[] args) throws IOException {

        //1. 设置配置类
        Configuration config = new Configuration();
        //设置hdfs
        config.set("fs.defaultFS","hdfs://10.90.100.101:9820");
        //2. 获取到文件系统对象
        FileSystem fs = FileSystem.get(config);
        //3.设置读取文件的路径
        Path src = new Path("/ifconfig.txt");
        //4.获取输入流
        FSDataInputStream in = fs.open(src);
        //5.使用IO工具类输出内容到终端
        IOUtils.copyBytes(in,System.out,config);
        //6.关流
        in.close();


    }
}
